import vue from '@vitejs/plugin-vue'
import Jsx from "@vitejs/plugin-vue-jsx"
import { resolve } from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import { defineConfig, loadEnv } from 'vite'
import { createHtmlPlugin } from "vite-plugin-html"

const config = loadEnv('development', './')

export default defineConfig({
  plugins: [
    vue(),
    Jsx(),
    AutoImport({
      imports: ['vue', 'vue-router'],
      dts: 'types/auto-imports.d.ts',
      resolvers: [
        ElementPlusResolver(),
      ],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
      dts: 'types/components.d.ts'
    }),
    createHtmlPlugin({
      inject: {
        data: {
          title: config.VITE_APP_TITLE
        },
      },
    }),
  ],

  server: {
    host: '0.0.0.0',
    port: 3000,
    open: false,
    proxy: {
      '^/api': {
        target: 'http://localhost:1234',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    },
  },

  resolve: {
    alias: {
      '@': resolve(__dirname, './src'),
    },
  },
})
